package world;

import java.io.Serializable;
import java.util.ArrayList;

import utility.Vector;
import control.GUI.Output;

public class World implements Serializable {

	private static final long serialVersionUID = -2333205005967703052L;
	private ArrayList<Person> people;
	private Vector size;
	private ArrayList<Weapon> weapons;

	public World() {

		people = new ArrayList<Person>();
		for (int c0 = 0; c0 < 10; c0++) {
			Person p = new Person(new Vector(Math.random() * 100,
					Math.random() * 100));
			people.add(p);
		}

		weapons = new ArrayList<>();
		for (int c0 = 0; c0 < 10; c0++) {
			weapons.add(new Weapon(new Vector(Math.random() * 100, Math
					.random() * 100)));
		}

		size = new Vector(100, 100);

	}

	public void tick(Output out) {
		for (Person p : people) {
			p.act(this, out);
		}
	}

	public void report(Output out) {
		for (int c0 = 0; c0 < people.size(); c0++) {
			if (people.get(c0).getHealth() > 0) {
				people.get(c0).report(out);
			} 
		}

	}

	public ArrayList<PhysicalObject> getObjectsInRange(Vector pos, double range) {
		ArrayList<PhysicalObject> obj = new ArrayList<PhysicalObject>();

		for (Person p : people) {
			if (pos.distance(p.position) < range) {
				obj.add(p);
			}
		}
		for (Weapon p : weapons) {
			if (pos.distance(p.position) < range) {
				obj.add(p);
			}
		}
		return obj;
	}

	/**
	 * @return All visible physical objects in the game world
	 */
	public ArrayList<PhysicalObject> getVisibleObjects() {
		ArrayList<PhysicalObject> l = new ArrayList<>();
		l.addAll(people);
		l.addAll(weapons);
		return l;
	}

	public Vector getSize() {
		return size;
	}
}
